#!/bin/bash
cd /workspace

# 设置Hadoop classpath
export CLASSPATH=""
for jar in /opt/hadoop-3.2.1/share/hadoop/common/*.jar; do
    CLASSPATH=$CLASSPATH:$jar
done
for jar in /opt/hadoop-3.2.1/share/hadoop/common/lib/*.jar; do
    CLASSPATH=$CLASSPATH:$jar
done
for jar in /opt/hadoop-3.2.1/share/hadoop/mapreduce/*.jar; do
    CLASSPATH=$CLASSPATH:$jar
done

echo "开始编译所有MapReduce任务..."
javac -encoding UTF-8 -classpath "$CLASSPATH" Task*.java

if [ $? -eq 0 ]; then
    echo "编译成功，打包JAR..."
    jar -cvf tasks.jar Task*.class
    rm -f *.class
    echo ""
    echo "编译完成！"
    ls -lh tasks.jar
else
    echo "编译失败！"
    exit 1
fi
